Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional key to the FieldExport target #100

Merged
merged 3 commits into from
Aug 30, 2022

Conversation

baijum
Copy link
Contributor

@baijum baijum commented Aug 23, 2022

FieldExport generates the key name with an output structure like
<namespace>.<FieldExport-resource-name>. This default naming structure
creates non-conflicting names as the keys. However, many applications
expect short names as keys. This is important, especially when the
Secret/ConfigMap is mounted as files; the file names are nothing but
the key names.

This PR adds an optional attribute (.spec.to.key) to specify the key
name in the FieldExport resource. If this attribute is specified,
use this key name instead of the default.

Signed-off-by: Baiju Muthukadan baiju.m.mail@gmail.com

Issue #, if available: aws-controllers-k8s/community#1410

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-bot ack-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 23, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Aug 23, 2022

Hi @baijum. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

FieldExport generates the key name with an output structure like
`<namespace>.<FieldExport-resource-name>`. This default naming structure
creates non-conflicting names as the keys. However, many applications
expect short names as keys. This is important, especially when the
Secret/ConfigMap is mounted as files; the file names are nothing but
the key names.

This PR adds an optional attribute (.spec.to.key) to specify the key
name in the FieldExport resource. If this attribute is specified,
use this key name instead of the default.

Proposal: aws-controllers-k8s/community#1410

Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baijum cool stuff! couple things for you inline :)

@@ -24,6 +24,7 @@ type FieldExportTarget struct {
// Namespace is marked as optional, so we cannot compose `NamespacedName`
Namespace *string `json:"namespace,omitempty"`
Kind FieldExportOutputType `json:"kind"`
Key *string `json:"key,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and add a docstring above here so that our API reference docs will include an explanation for the field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added docs. a974e46

@@ -296,6 +296,9 @@ func (r *fieldExportReconciler) writeToConfigMap(
) error {
// Construct the data key
key := fmt.Sprintf("%s.%s", desired.Namespace, desired.Name)
if desired.Spec.To.Key != nil {
key = *desired.Spec.To.Key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user enters an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the logic to consider empty strings. With an empty string value, the key will fall back to <namespace>.<FieldExport-resource-name>. a974e46

Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
@a-hilaly
Copy link
Member

/ok-to-test

@ack-bot ack-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 24, 2022
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! left one question

@@ -340,6 +343,9 @@ func (r *fieldExportReconciler) writeToSecret(
) error {
// Construct the data key
key := fmt.Sprintf("%s.%s", desired.Namespace, desired.Name)
if desired.Spec.To.Key != nil && strings.TrimSpace(*desired.Spec.To.Key) != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we handle cases where Spec.To is nil? to avoid nil panics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. f6caece

Signed-off-by: Baiju Muthukadan <baiju.m.mail@gmail.com>
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! 👍

@baijum
Copy link
Contributor Author

baijum commented Aug 30, 2022

Once this PR is merged. I am planning to write a blog. Here is the early draft: https://gist.github.com/baijum/96158408eaf544f692acfad42f2b49df

Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome addition. It's something I considered in the original design, but left it out just because I thought it wasn't necessary for an initial release. Thank you!

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 30, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Aug 30, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, baijum, RedbackThomson

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,RedbackThomson]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
5 participants